<template>
	<view class="contoan">
		<top-back-navbar position="fixed" title="积分兑换" background="#040A1A" color="#fff"></top-back-navbar>
		<cxsytabbars :current="0" style="position: relative;z-index: 1;"></cxsytabbars>
		<view class="jifen_box">

			<view class="item" v-for="item in jifen_goods_info" @click="show_model_duihuan(item)">
				<image :src="item.thumb" style="width: 100%;height: 75%;border-radius: 8px;" mode=""></image>

				<view class="" style="width: 100%; padding: 0 8px; padding-top: 5px;">
					<view class="num"
						style="font-weight: 800;font-size: 16px;position: relative;top: -10px;white-space: nowrap; overflow: hidden;">
						{{item.title}}
					</view>
					<view class=""
						style="display: flex;position: relative;top: -18px;justify-content: space-between;align-items: center;">
						<view class="num" style="font-weight: 800;font-size: 16px;">
							¥{{item.marketprice}}
						</view>
						<view class=""
							style="background-color: #7316F3; color: #fff;border-radius: 50px;padding: 0 10px;margin-right: 5px;">
							兑换
						</view>
					</view>
				</view>

			</view>


		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {


				page: 1,
				cate: 1294,
				res: [],
				res_list: [],
				goods_info: [],
				jifen_goods_info: [],
				openid: ''
			};
		},
		onLoad: function(e) {
			console.log(e);
			var _this = this
			var id = uni.getStorage({
				key: 'openid',
				success: function(res) {
					var id = res.data

					_this.openid = id
					_this.getGoodsList(e.gift)
				},
				fail: function(err) {
					uni.hideLoading()
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			});
			
		},
		methods: {
			show_model_duihuan(value) {
				var _this = this
				uni.showModal({
					title: `使用积分兑换${value.title}商品`,
					placeholderText: '输入数量(件)',
					editable: true,
					success(res) {

						if (res.confirm) {
							_this.duihuan_sure(res.content, value.id)
						}
					}
				})
			},
			duihuan_sure(num, id) {

				uni.request({
					url: `${this.$BASE_URL}/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=api.index.cxrz_submit&app=1`,
					method: 'POST',
					data: {
						'openid': this.openid,
						'num': num,
						'id': id,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						var data = res.data
						uni.showToast({
							icon: 'none',
							title: data.message
						})
					},
					fail: () => {},
					complete: () => {}
				})
			},
			getGoodsList(gift) {

				// if(!this.contentText)return;
				uni.showLoading()
				uni.request({
					url: this.$BASE_URL +
						'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=goods.get_list&keywords=&isrecommand=&ishot=&isnew=&isdiscount=&issendfree=&istime=&order=&by=&merchid=&gift=' +
						gift,

					success: res => {
						let list = Array.isArray(res.data.result.list) ? res.data.result.list : []
						console.log(list);

						this.jifen_goods_info = list
					},
					fail: () => {},
					complete: () => {
						uni.hideLoading();
					}
				});
			},
			todetails(item) {
				var path = `/pages/goods/detail?goodsid=${item.id}&type='cxsy'`
				uni.navigateTo({
					url: path
				});

			},
		}
	}
</script>

<style lang="less">
	* {
		margin: 0;
		padding: 0;
	}

	page {
		height: 100%;
		width: 100vw;
		height: 180vh;
		background: url('/static/zn/home_bg.png') 0 0 no-repeat;
		background-size: 150% 106%;
		position: relative;
		overflow: auto;

	}
.num{

		background: linear-gradient(to bottom, #FBEDB9, #FFB85C, );
		align-items: center;
		background-clip: text;
		color: transparent;

	}
	.contoan {
		width: 100vw;
		padding: 10px 10px;
	}

	.jifen_box {
		// margin-top: 25rpx;
		width: 100%;
		// height: 100vh;
		padding-bottom: ;
		background: url('/static/zn/jifen_box.png') 0 0 no-repeat;
		background-size: 100% 100%;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 10px 10px;
		.item {
			margin-top: 10rpx;
			width: 49%;
			height: 27vh;

			background: url('/static/zn/jifen_item.png') 0 0 no-repeat;
			background-size: 100% 100%;
			padding: 9px;

		}
	}

	.shop_item_box {
		.title {
			width: 100%;
			text-align: center;
			color: #F4D8B2;
			font-size: 20px;
			font-weight: 800;
		}

		.price {
			width: 100%;
			text-align: center;
			color: #F4D8B2;
			font-size: 20px;
			font-weight: 800;
		}
	}
</style>